package com.dmall.sort.com.dmall.heap;

import org.junit.Test;

import java.util.PriorityQueue;
import java.util.Random;

public class HeapTest {

    @Test
    public void testMaxHeap() {
        Heap<Integer> heap = new MaxHeap<>(10);
        Random random = new Random();
        for (int i = 0; i < 10; i++) {
            heap.add(random.nextInt(50));
        }
        while (!heap.isEmpty()) {
            System.out.println(heap.extract());
        }
    }

    @Test
    public void testMinHeap() {
        Heap<Integer> heap = new MinHeap<>(10);
        Random random = new Random();
        for (int i = 0; i < 10; i++) {
            heap.add(random.nextInt(50));
        }

        while (!heap.isEmpty()) {
            System.out.println(heap.extract());
        }
    }

    @Test
    public void testPriorityQueue() {
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        Random random = new Random();
        for (int i = 0; i < 10; i++) {
            queue.offer(random.nextInt(50));
        }

        while (!queue.isEmpty()) {
            System.out.println(queue.poll());
        }
    }
}
